package com.gtw;

import com.gtw.memento.Caretaker;
import com.gtw.memento.Originator;
import com.gtw.memento.clone.CloneOriginator;
import com.gtw.memento.manyMementor.ManyMementorCaretaker;
import com.gtw.memento.manyState.ManyStateOriginator;

public class Client {

    public static void main(String[] args) {
        Originator originator = new Originator();
        Caretaker taker = new Caretaker();
        //创建备忘录
        taker.setMementor(originator.createMementor());
        //恢复备忘录
        originator.restoreMementor(taker.getMementor());

        /**
         * 通过clone方式
         */
        CloneOriginator cloneOriginator = new CloneOriginator();
        cloneOriginator.setState("clone方式状态前");
        System.out.println("当前状态是:" + cloneOriginator.getState());
        //建立备份
        cloneOriginator.createMementor();
        //修改状态
        cloneOriginator.setState("clone方式状态后");
        System.out.println("当前状态是:" + cloneOriginator.getState());
        //恢复之前状态
        cloneOriginator.restoreMementor();
        System.out.println("当前状态是:" + cloneOriginator.getState());

        /**
         * 全属性备份
         */
        ManyStateOriginator manyStateOriginator = new ManyStateOriginator();
        com.gtw.memento.manyState.Caretaker taker1 = new com.gtw.memento.manyState.Caretaker();
        manyStateOriginator.setState1("11");
        manyStateOriginator.setState2("22");
        manyStateOriginator.setState3("33");
        System.out.println(manyStateOriginator);
        //创建备忘录
        taker1.setMementor(manyStateOriginator.createMementor());
        manyStateOriginator.setState1("aa");
        manyStateOriginator.setState2("bb");
        manyStateOriginator.setState3("cc");
        System.out.println(manyStateOriginator);

        manyStateOriginator.restoreMementor(taker1.getMementor());
        System.out.println(manyStateOriginator);

        System.out.println("------------以下是多备份-------------");

        /**
         * 多备份
         */
        ManyStateOriginator manyStateOriginator1 = new ManyStateOriginator();
        ManyMementorCaretaker caretaker2 = new ManyMementorCaretaker();
        manyStateOriginator1.setState1("11");
        manyStateOriginator1.setState2("22");
        manyStateOriginator1.setState3("33");
        System.out.println(manyStateOriginator1);
        //创建备忘录
        caretaker2.setMementor("1", manyStateOriginator1.createMementor());

        manyStateOriginator1.setState1("aa");
        manyStateOriginator1.setState2("bb");
        manyStateOriginator1.setState3("cc");
        System.out.println(manyStateOriginator1);
        //创建备忘录
        caretaker2.setMementor("2", manyStateOriginator1.createMementor());

        manyStateOriginator1.setState1("AA");
        manyStateOriginator1.setState2("BB");
        manyStateOriginator1.setState3("CC");
        System.out.println(manyStateOriginator1);
        //创建备忘录
        caretaker2.setMementor("3", manyStateOriginator1.createMementor());

        manyStateOriginator1.restoreMementor(caretaker2.getMementor("1"));
        System.out.println(manyStateOriginator1);
    }
}
